Page({
  data: {
    serviceType: '',
    date: '',
    startDate: '',
    timeSlots: ['08:00-10:00', '10:00-12:00', '14:00-16:00', '16:00-18:00'],
    timeSlotIndex: 0,
    // 家政保洁相关数据
    cleaningOptions: [
      { name: 'regular', value: '日常保洁', checked: true },
      { name: 'deep', value: '深度清洁' },
      { name: 'window', value: '窗户清洁' }
    ],
    cleaningArea: '',
    cleaningNote: '',
    // 快递入户相关数据
    expressCompany: '',
    expressNumber: '',
    expressNote: '',
    // 日用品订购相关数据
    shoppingList: '',
    shoppingNote: '',
    // 老人照护相关数据
    careDurations: ['2小时', '4小时', '8小时', '全天'],
    durationIndex: 0,
    healthNeeds: '',
    elderlyNote: ''
  },

  onLoad: function(options) {
    // 设置默认日期为今天
    const today = new Date();
    const year = today.getFullYear();
    const month = String(today.getMonth() + 1).padStart(2, '0');
    const day = String(today.getDate()).padStart(2, '0');
    
    this.setData({
      startDate: `${year}-${month}-${day}`,
      serviceType: options.type || ''
    });
  },

  bindDateChange: function(e) {
    this.setData({ date: e.detail.value });
  },

  bindTimeSlotChange: function(e) {
    this.setData({ timeSlotIndex: e.detail.value });
  },

  bindDurationChange: function(e) {
    this.setData({ durationIndex: e.detail.value });
  },

  // 家政保洁选项改变
  bindCleaningChange: function(e) {
    const selectedValues = e.detail.value;
    const newCleaningOptions = this.data.cleaningOptions.map(option => {
      return {
        ...option,
        checked: selectedValues.includes(option.value)
      };
    });
    this.setData({ cleaningOptions: newCleaningOptions });
  },

  // 输入框变化
  onInput: function(e) {
    const { field } = e.currentTarget.dataset;
    this.setData({ [field]: e.detail.value });
  },

  // 提交预约
  submitReservation: function() {
    const { serviceType } = this.data;
    let formData = {};
    
    // 根据服务类型收集不同的表单数据
    switch(serviceType) {
      case 'cleaning':
        formData = {
          type: 'cleaning',
          date: this.data.date,
          timeSlot: this.data.timeSlots[this.data.timeSlotIndex],
          cleaningType: this.data.cleaningOptions,
          area: this.data.cleaningArea,
          note: this.data.cleaningNote
        };
        break;
      case 'express':
        formData = {
          type: 'express',
          company: this.data.expressCompany,
          number: this.data.expressNumber,
          note: this.data.expressNote
        };
        break;
      case 'shopping':
        formData = {
          type: 'shopping',
          list: this.data.shoppingList,
          note: this.data.shoppingNote
        };
        break;
      case 'elderly':
        formData = {
          type: 'elderly',
          duration: this.data.careDurations[this.data.durationIndex],
          healthNeeds: this.data.healthNeeds,
          note: this.data.elderlyNote
        };
        break;
    }
    
    // 这里添加表单验证逻辑
    if (!formData.date && serviceType !== 'express' && serviceType !== 'shopping') {
      wx.showToast({
        title: '请选择服务日期',
        icon: 'none'
      });
      return;
    }
    
    // 实际项目中，这里会调用API提交表单数据
    console.log('提交预约数据:', formData);
    
    wx.showToast({
      title: '预约成功',
      icon: 'success'
    });
  }
});